import random

from constants.global_variable import account_index_generator, android_versions, chrome_versions, devices, \
    hardware_configs, proxy_user_prefix


class ProxyUtils:
    @staticmethod
    def generate_proxy_user():
        return proxy_user_prefix + str(account_index_generator.get_next_account())

    @staticmethod
    def generate_android_ua():
        android_version = random.choice(android_versions)
        chrome_version = random.choice(chrome_versions)
        device_model = random.choice(devices)
        ua = f"Mozilla/5.0 (Linux; Android {android_version}; {device_model}) " \
             f"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{chrome_version} Mobile Safari/537.36"
        return ua

    @staticmethod
    def generate_cpu_and_memory():
        # 合理匹配的配置组合
        # 从组合中随机挑一个
        cpu_cores, memory_gb = random.choice(hardware_configs)
        return {
            "hardware_concurrency": cpu_cores,
            "device_memory": memory_gb
        }